/**
 * $Id$
 * @author mcanovas
 * @date   Feb 29, 2012 12:53:55 PM
 *
 * Copyright (C) 2012 Scytl Secure Electronic Voting SA
 *
 * All rights reserved.
 *
 */
package org.sk.gsync.app.spring;

import javax.sql.DataSource;

import org.h2.jdbcx.JdbcDataSource;
import org.sk.gsync.app.mybatis.FolderService;
import org.sk.gsync.app.mybatis.QueueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

@Configuration
@PropertySource("/database.properties")
public class DatabaseSpringConfig {

    @Autowired
    private Environment environment;

    private static final String URL = "db.url";

    private static final String USER = "db.user";

    private static final String PASSWORD = "db.password";

    @Bean(name = "datasource")
    public DataSource getDataSource() {
        JdbcDataSource jdbcDataSource = new JdbcDataSource();
        jdbcDataSource.setURL(environment.getProperty(URL));
        jdbcDataSource.setUser(environment.getProperty(USER));
        jdbcDataSource.setPassword(environment.getProperty(PASSWORD));
        return jdbcDataSource;
    }

    @Bean(name = "folderService")
    public FolderService getFolderService() {
        return new FolderService();
    }

    @Bean(name = "queueService")
    public QueueService getQueueService() {
        return new QueueService();
    }
}
